package com.study.zzedu.ui.schoolroll.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.study.zzedu.R;
import com.study.zzedu.adapter.CourseDetailAdapter;
import com.study.zzedu.entity.CourseDetailItem;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.Utils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static com.study.zzedu.ui.schoolroll.SchoolRollActivity.schoolRollInfo_personalInfo;

/**
 */

public class PersonalInfoFragment extends Fragment {

    private List<CourseDetailItem> dataList = new ArrayList<CourseDetailItem>();
    CourseDetailAdapter courseDetailAdapter;
    RecyclerView mRecyclerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_person_info, container, false);
        initView(rootView);
        return rootView;
    }
    protected void initView(View view) {

        mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_list_data);
        LinearLayoutManager lm = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(lm);

        try {
            if(schoolRollInfo_personalInfo == null)
                return;
            JSONObject job = schoolRollInfo_personalInfo;
            dataList.add(new CourseDetailItem("姓名", Utils.getDefaultStringValue(job,"name"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("曾用名",Utils.getDefaultStringValue(job,"oldName"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("性别编码",Utils.getDefaultStringValue(job,"sexCode"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("性别",Utils.getDefaultStringValue(job,"sex"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("民族编码",Utils.getDefaultStringValue(job,"nationCode"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("民族",Utils.getDefaultStringValue(job,"nation"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("出生年月",Utils.getDefaultStringValue(job,"birth"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("政治面貌",Utils.getDefaultStringValue(job,"political"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("证件类型编码",Utils.getDefaultStringValue(job,"cardTypeCode"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("证件类型",Utils.getDefaultStringValue(job,"cardType"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("证件号",Utils.getDefaultStringValue(job,"cardId"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("住址",Utils.getDefaultStringValue(job,"address"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("邮箱",Utils.getDefaultStringValue(job,"mail"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("qq",Utils.getDefaultStringValue(job,"qq"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("当前工作单位",Utils.getDefaultStringValue(job,"newAddr"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("手机号",Utils.getDefaultStringValue(job,"phone"),CourseDetailItem.TYPE_STRING));
            dataList.add(new CourseDetailItem("邮编",Utils.getDefaultStringValue(job,"postCode"),CourseDetailItem.TYPE_STRING));

            view.findViewById(R.id.rl_default_personal_info).setVisibility(View.GONE);
        }catch (Exception e){
            LogUtil.e("Exception",getActivity()+" "+e.toString());
            e.toString();
        }
        courseDetailAdapter = new CourseDetailAdapter(dataList);
        //mRecyclerView.addItemDecoration(new SpacesItemDecoration(30));
        mRecyclerView.setAdapter(courseDetailAdapter);
    }
}
